# -*- coding: utf-8 -*-
# author yzs
# date 2018-12-17
#
# 最小交换次数
# Description
# Given an array of N distinct elementsA[ ], find the minimum number of swaps required to sort the array.
# Your are required to complete the function which returns an integer denoting the minimum number of swaps,
# required to sort the array.
# Input
# The first line of input contains an integer T denoting the no of test cases .
# Then T test cases follow . Each test case contains an integer N denoting the no of element of the array A[ ].
# In the next line are N space separated values of the array A[ ] .(1<=T<=100;1<=N<=100;1<=A[] <=1000)
# Output
# For each test case in a new line output will be an integer denoting minimum umber of swaps
# that are required to sort the array.
# Sample Input 1 
# 2
# 4
# 4 3 2 1
# 5
# 1 5 4 3 2
# Sample Output 1
# 2
# 2
# 解题思路：插入排序的基本操作，交换时计算次数即可


def select_sort(array):
    n = len(array)
    count = 0
    for i in range(0,n):
        min = i                             #最小元素下标标记
        for j in range(i+1,n):
            if array[j] < array[min] :
                min = j                     #找到最小值的下标
        if(min != i):
            array[min], array[i] = array[i], array[min]   #交换两者
            count += 1
    print(count)


T = int(input().strip())
for i in range(T):
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    A = A[:N]
    select_sort(A)